import java.util.ArrayList;
import java.util.List;

/**
 * @author tmh
 * @date 2024/9/27 21:51
 * @description
 */
public class T78子集 {
    private List<List<Integer>> result = new ArrayList<>();
    private List<Integer> list = new ArrayList<>();
    private int len = 0;


    public List<List<Integer>> subsets(int[] nums) {
        len = nums.length;
        dfs(0, nums);
        return result;
    }

    private void dfs(int index, int[] nums) {
        result.add(new ArrayList<>(list));
        if (index>=len){
            return;
        }
        for (int i = index; i < len; i++) {
            list.add(nums[i]);
            dfs(i+1, nums);
            list.remove(list.size() - 1);
        }
    }
}
